﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TPLOAWebService.Models
{
    public class MemberRepository : IMemberRepository
    {
        public IEnumerable<Member> GetAll()
        {
            return TPLOADBManager.GetAllMember().Cast<Member>();
        }

        public Member Get(string id)
        {
            return TPLOADBManager.GetMemberByID(id);
        }

        public Member Add(Member item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (TPLOADBManager.InsertMember(item) == 0)
            {
                return null;
            }
            else
            {
                return item;
            }
        }

        public void Remove(string id)
        {
            TPLOADBManager.DeleteMember(id);
        }

        public bool Update(Member item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (TPLOADBManager.UpdateMember(item) == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}